package com.qianfeng.ttgy.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.lidroid.xutils.BitmapUtils;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.qianfeng.ttgy.R;
import com.qianfeng.ttgy.bean.Banner;

import java.util.List;

/**
 * Created by Administrator on 2015/8/4.
 */
public class MainAdapter extends BaseAdapter{
    private Context context;
    private List<Banner> banners;
    private BitmapUtils bitmapUtils;
    private LayoutInflater inflater;
   // private List<Banner> list;
    public MainAdapter( Context context,List<Banner> banners,BitmapUtils bitmapUtils) {
        this.context = context;
        this.banners = banners;
        this.bitmapUtils = bitmapUtils;
        inflater = LayoutInflater.from(context);

    }
    @Override
    public int getCount() {
        return banners.size();
    }

    @Override
    public Object getItem(int position) {
        return banners.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder vh;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.adapter_main_fragment, parent, false);
            vh = new ViewHolder(convertView);
            convertView.setTag(vh);
        } else {
            vh = (ViewHolder) convertView.getTag();
        }
        bitmapUtils.display(vh.imageView,banners.get(position).getPhoto());
        return convertView;
    }



    private static class ViewHolder {
        @ViewInject(R.id.adapter_main_imageView)
        private ImageView imageView;
        public ViewHolder(View convertView) {
            ViewUtils.inject(this,convertView);
        }
    }
}
